class Solution {
public:
https://leetcode.cn/problems/find-largest-value-in-each-tree-row/description/ 
   vector<int> largestValues(TreeNode* root) {
        vector<int> ret;
        if(!root)
            return ret;
        queue<TreeNode*> q;
        q.push(root);

        while(!q.empty())
        {
            int _max=-INT_MAX-1;
            int k=q.size();
            //出k个结点
            while(k--)
            {
                TreeNode*t=q.front();
                q.pop();
                _max=max(_max,t->val);
                //带孩子入队列
                if(t->left) q.push(t->left);
                if(t->right) q.push(t->right);
            }
            ret.push_back(_max);
        }
        return ret;
    }
};




